//A变成B的最小操作次数，AB都是0101字符串，操作:对区间l-r作比特反转。
#include<iostream>
#include<set>
using namespace std;

struct linknode
{
	int val;
	linknode* next;
	linknode(int v)
	{
		val = v;
		next = nullptr;
	}
};

void show(linknode* head)
{
	while (head)
	{
		cout << head->val;
		head = head->next;
	}
}
//void reverse(linknode* head)
//{
//	linknode* p, * p_n;
//	p = head;
//	int count = 0;
//	while (p)
//	{
//		count++;
//		p = p->next;
//	}
//	int count1 = 0;
//	int count2 = 0;
//	while (p)
//	{
//		count++;
//		if (count1 == count / 2)
//		{
//			stack<linknode*> s;
//			while (p)
//			{
//				s.push(p);
//			}
//			while (!s.empty()&&count2<=count/2)
//			{
//				s.top();
//			}
//		}
//		p = p->next;
//	}
//}
void reverse(linknode* &head)
{
	linknode* pre = head;
	linknode* nex = head->next;
	while (pre!= nullptr)
	{
		
		linknode* tmp = nex->next;
		nex->next = pre;
		pre->next = tmp;
		pre = nex;
		nex = tmp;
	}
	//return pre;
}
linknode* reverse1(linknode* head, linknode*& new_head)
{
	if (head->next== nullptr)
	{
		new_head = head;
		return head;
	}
	else
	{
		linknode* p=reverse1(head->next, new_head);
		p->next = head;
		head->next = nullptr;
		return head;
	}
}
//5 1 2 3 4 5
linknode* mid(linknode* head)
{
	int count = 0;
	linknode* q = head;
	linknode* s = head;
	while (head)
	{
		if (count&1)
		{
			s = s->next;
		}
		count++;
		head = head->next;
	}
	return s;

}

string change(int l, int r, string A)
{
	for (int i = l; i <= r; i++)
	{
		if (A[i] == '0') { A[i] == '1'; }
		else
		{
			A[i] == '0';
		}
	}
	return A;
}
void digui(set<string>&s, string A,string B,int count)
{
	if (s.count(A) == 1)
	{
		return;
	}
	for (int i = 0; i <= A.size(); i++)
	{
		for (int j = 0; j <= i; j++)
		{
			string tmp = change(i, j, A);
			if ( tmp == B)
			{
				cout << count;
			}
			else
			{
				s.insert(tmp);
				digui(s, tmp, B, count+1);
				s.erase(tmp);
			}
		}
	}
}
int main()
{
	unordered_map<int, int>m;

	
	int n;
	cin >> n;
	string A;
	string B;
	A.resize(n);
	B.resize(n);
	for (int i = 0; i<n; i++)
	{
		cin >> A[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> B[i];
	}
	set<string>s;
	digui(s, A, B, 0);
}